﻿using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.JSInterop.Infrastructure;
using PoemGame.Domain.GameAggregate;
using PoemGame.Domain.Services;
using PoemGame.Domain.Services.Factory.WebApi;
using PoemGameServiceWebApi.Dtos;
using PoemGameWebApiService.Shared;

namespace PoemGameServiceWebApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class PoemGameServiceController : ControllerBase
    {
        private readonly IDomainServiceFactory<ICheckAnswerService> _answerServiceFactory;
        private readonly IDomainServiceFactory<ICheckGameConditionService> _gameConditionServiceFactory;

        public PoemGameServiceController(IDomainServiceFactory<ICheckAnswerService> answerServiceFactory, IDomainServiceFactory<ICheckGameConditionService> gameConditionServiceFactory)
        {
            _answerServiceFactory = answerServiceFactory;
            _gameConditionServiceFactory = gameConditionServiceFactory;
        }

        [HttpPost("CheckAnswer")]
        public async Task<bool> CheckAnswer(PoemGameCheckAnswerServiceDto dto)
        {
            var service = _answerServiceFactory.GetService(new GameType(dto.Game_Main_Type, dto.Game_Sub_Type));
            return await service.CheckAnswer(dto.Input, dto.Answer);
        }

        [HttpPost("CheckCondition")]
        public async Task<bool> CheckCondition(PoemGameCheckConditionServiceDto dto)
        {
            var service = _gameConditionServiceFactory.GetService(new GameType(dto.Game_Main_Type, dto.Game_Sub_Type));
            return await service.CheckGameCondition(dto.Condition);
        }
    }
}
